<template>
	<view>
		<u-form :model="form" ref="uForm">
			<u-form-item label="岗位" prop="userInfo.sex" borderBottom @click="showJob = true; " ref="item1">
				<u--input v-model="form.post" disabled disabledColor="#ffffff" placeholder="请选择" border="none">
				</u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
		</u-form>
		<u-action-sheet :show="showJob" :actions="actions" @close="showJob = false" @select="sexSelect">
		</u-action-sheet>


		<view class="chooseTime" @click="show=true">
			<text class="choose">选择班次</text><br>
			<text class="time">{{time?items[active].text+' '+time.time:'可添加多个时间'}}</text>

			<view class="pleaseChoose">请选择<u-icon name="arrow-right"
					style="display: inline-block;position: relative;top: -4rpx;"></u-icon>
			</view>
		</view>
		<view
			style="background-color: #fff;padding-left: 32rpx;padding-right: 32rpx;padding-bottom: 24rpx;margin-bottom: 180rpx;">
			<text class="reasonTitle">请假理由</text>
			<u--textarea v-model="reason" placeholder="请输入请假理由" :height='380' border='none' maxlength='-1'>
			</u--textarea>
			<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10">
			</u-upload>
		</view>

		<view class="btn" @click="">
			<u-button type="primary" class="leave">提交</u-button>
		</view>
		<u-popup :show="show" :round="10" mode="bottom" @close="close" @open="open">
			<view style="position: relative;">
				<view style="text-align: center;margin-top: 28rpx;margin-bottom: 28rpx;font-size: 28rpx;color: #333;">
					选择班次</view>
				<image src="../../static/images/close_icon.png"
					style="width: 26rpx;height: 26rpx;position: absolute;right: 32rpx;top: 34rpx;" @click="close()">
				</image>
				<van-tree-select height="55vw" :items="items" :main-active-index.sync="active">
					<template #content>
						<view v-if="active === 0" class="timeBox">
							<view class="timeItem" :class="item == time?'timeBlue':''" v-for="(item, i) in timeList"
								:key="i" @click="changeTime(item)">
								{{item.time}}
							</view>
						</view>
						<view v-else-if="active === 1">2222</view>
					</template>
				</van-tree-select>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timeList: [{
						time: '9:00-10:00',
					},
					{
						time: '10:00-11:00',
					},
					{
						time: '9:00-10:00',
					},
				],
				time: '',
				show: false,
				showJob: false,
				form: {
					post: '',
				},
				actions: [{
						name: '思想动态观察岗',
					},
					{
						name: '思想动态观察岗1',
					},
					{
						name: '思想动态观察岗2',
					},
				],
				reason: '',
				fileList: [],

				active: 0,
				items: [{
						text: '2月23日(星期三)'
					},
					{
						text: '2月24日(星期三)'
					},
					{
						text: '2月24日(星期三)'
					},
					{
						text: '2月24日(星期三)'
					},
					{
						text: '2月24日(星期三)'
					},
					{
						text: '2月24日(星期三)'
					},
				],
			}
		},
		methods: {
			sexSelect(e) {
				this.form.post = e.name
				this.$refs.uForm.validateField('form.post')
			},

			//图片上传
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			open() {},
			close() {
				this.show = false
			},
			changeTime(item) {
				this.time = item
				this.close()
			},
		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #FAFAFA;
	}

	.van-tree-select__nav {
		flex: 1.25;
	}

	.van-sidebar-item--select::before {
		background-color: #2674FF;
	}

	.chooseTime {
		background-color: #fff;
		margin-top: 16rpx;
		margin-bottom: 16rpx;
		padding: 14rpx 0;
		position: relative;

		.choose {
			margin: 0 32rpx;
			font-weight: 400;
			color: #4A4E4C;
			font-size: 32rpx;
		}

		.time {
			margin: 0 32rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #8D9893;
		}

		.pleaseChoose {
			position: absolute;
			right: 32rpx;
			top: 36rpx;
			color: #666666;

		}
	}

	.choose {
		margin: 0 32rpx;
		font-weight: 400;
		color: #4A4E4C;
		font-size: 32rpx;
	}

	/deep/.uni-input-placeholder {
		color: #666 !important;
	}

	/deep/.u-input__content__field-wrapper__field {
		line-height: 27rpx;
	}

	/deep/.u-form-item {
		background-color: #fff;
	}

	/deep/.u-form-item__body {
		margin: 0 32rpx;
	}

	/deep/.uni-input-wrapper {
		text-align: right;
	}

	/deep/.u-form-item__body__left {
		color: #333333;
		font-size: 32rpx;
	}

	/deep/.u-form-item__body__right__content__slot {
		.uni-input-input {
			font-size: 28rpx;
			font-weight: 400;
			color: #666666;
			text-align: right;
		}

	}

	/deep/.u-textarea {
		padding: 0;
	}

	/deep/.uicon-arrow-right {
		font-size: 14rpx !important;
		top: 4rpx !important;
	}

	.reasonTitle {
		margin-top: 24rpx;
		margin-bottom: 16rpx;
		color: #333333;
		font-weight: 400;
		font-size: 32rpx;
	}

	.u-form {
		margin-top: 24rpx;
		margin-bottom: 16rpx;

		/deep/.u-line {
			display: none !important;
		}
	}

	.btn {
		width: 100%;
		height: 148rpx;
		background: #FFFFFF;
		display: block;
		position: fixed;
		bottom: 0;
		box-shadow: 0px -4px 8px 0px rgba(0, 0, 0, 0.05);
		z-index: 5;

		.leave {
			width: 686rpx;
			height: 100rpx;
			background: #2674FF;
			border-radius: 8rpx;
			margin-top: 24rpx;
		}
	}

	.timeBox {
		display: flex;
		flex-wrap: wrap;
		margin: 18rpx 24rpx;

		.timeItem {
			padding: 34rpx 28rpx;
			flex: 0 0 calc(50% - 9rpx);
			font-size: 24rpx;
			border-radius: 8rpx;
			color: #666666;
			background: #F4F4F4;
			margin-bottom: 16rpx;
		}

		.timeItem:nth-child(odd) {
			margin-right: 9rpx;
		}

		.timeItem:nth-child(even) {
			margin-left: 9rpx;
		}

		.timeBlue {
			color: #2674FF;
			background: #E9F1FF;
		}
	}
</style>
